package vg.services.graph_view_manager.realization.graph_view.smart_graph_view.realization.actions;

import org.apache.commons.lang.mutable.MutableBoolean;
import vg.interfaces.ll_services.data_base_service.data.graph.Attribute;
import vg.interfaces.ll_services.data_base_service.data.graph.Edge;
import vg.interfaces.ll_services.data_base_service.data.graph.Vertex;
import vg.services.graph_view_manager.interfaces.graph_view.IGraphRenderer;

import java.util.HashMap;
import java.util.Map;

/**
 * Gets attributes for selected vertex attributes.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public abstract class GetSelectedElementAttributes extends DefaultActionAdapter {
    private Map<Vertex, Map<Attribute, MutableBoolean>> selectedVertexAttributes;
    private Map<Edge, Map<Attribute, MutableBoolean>> selectedEdgeAttributes;

    protected GetSelectedElementAttributes() {
        super("get selected element attributes");
    }

    @Override
    public void action(final IGraphRenderer graphRenderer) {
        selectedVertexAttributes = graphRenderer.getSelectedVertexAttributes();
        selectedEdgeAttributes = graphRenderer.getSelectedEdgeAttributes();
    }

    public Map<Attribute, MutableBoolean> getSelectedVertexAttributes() {
        final Map<Attribute, MutableBoolean> result = new HashMap<Attribute, MutableBoolean>();

        if (selectedVertexAttributes != null) {
            for (Map<Attribute, MutableBoolean> buf : selectedVertexAttributes.values()) {
                if (buf != null)
                    result.putAll(buf);
            }
        }

        return result;
    }

    public Map<Attribute, MutableBoolean> getSelectedEdgeAttributes() {
        final Map<Attribute, MutableBoolean> result = new HashMap<Attribute, MutableBoolean>();

        if (selectedEdgeAttributes != null) {
            for (Map<Attribute, MutableBoolean> buf : selectedEdgeAttributes.values()) {
                if (buf != null)
                    result.putAll(buf);
            }
        }

        return result;
    }
}
